#include <iostream>

using namespace std;

class A{
public:
    A(int i = 0):_i(new int(i)){
        cout << "A(int i = 0)" << endl;
    }
    A(const A& that){
        this->_i = new int;
        *(this->_i) = *(that._i);
        cout << "A(const A& that)" << endl;
    }
    A& operator=(const A& that){
        if(this != &that){
            delete _i;
            this->_i = new int;
            *(this->_i) = *(that._i);
        }
        cout << "A& operator=(const A& that)" << endl;
        return *this;
    }
    A(A&& that){//移动构造
        this->_i = that._i;
        that._i = nullptr;
        cout << "A(A&& that){" << endl;
    }
    A& operator=(A&& that){//移动赋值
        if(this != &that){
            delete this->_i;
            this->_i = that._i;
            that._i = nullptr;
        }
        cout << "A& operator=(A&& that){" << endl;
        return *this;
    }
    ~A(){
        if(this->_i != nullptr)
            cout << "~" << endl;
            delete _i;
        cout << "~A()" << endl;
    }
    int* _i;
};

int main()
{
    A a;
    A b(a);
    A c(std::move(a));
    A d;
    d = b;
    c = std::move(b);
    return 0;
}
